<template>
  <div>
    <a-card :bordered="false">
      <f-table ref="table" size="default" rowKey="identityId" :columns="columns" :operator="operator" :params="queryParam" :api="api.process.authList" :autoLoad="false" :showPagination="false" :multiple="false">
        <span slot="action" slot-scope="text, record">
          <template>
             <a href="javascript:;" @click="removeAuth(record)">删除</a>
          </template>
        </span>
      </f-table>
    </a-card>
    <a-modal title="流程授权" :visible="authModal" width="600px" @cancel="handleCancel" @ok="handleSubmit">
      <f-form ref="form" :action="api.process.authAdd" :form-key="this.formItem.identityId">
        <f-form-item label="授权类型" name="identityType" type="radio" value-key="value" label-key="label" :data="api.process.identityType" :value="formItem.identityType"/>
        <f-form-item label="授权ID" name="identityId" :required="true" :value="formItem.identityId"/>
      </f-form>
    </a-modal>
  </div>
</template>

<script>
  import api from './js/api'

  export default {
    name: 'ProcessAuth',
    components: {},
    data() {
      return {
        api: Object.assign(api, this.api),
        authModal: false,
        formItem: {
          identityType: '',
          processDefinitionId: '',
          identityId: ''
        },
        //列表初始化查询参数
        queryParam: {
          processDefinitionId: '',
          identityType: '',
          identityId: ''
        },
        // 表头
        columns: [
          {
            title: '授权ID',
            align: 'center',
            dataIndex: 'identityId'
          },
          {
            title: '授权类型',
            dataIndex: 'identityType'
          },
          {
            title: '授权名称',
            align: 'center',
            dataIndex: 'identityName'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        //操作按钮
        operator: [
          {
            name: '添加授权',
            icon: 'plus',
            that: this,
            handler: (table) => {
              this.authModal = true
            }
          }
        ]
      }
    },
    computed: {},
    methods: {
      setData(data) {
        if (data && data.procDefId) {
          this.queryParam.processDefinitionId = data.procDefId
          this.$refs['table'].refresh(false)
        }
      },
      removeAuth(record) {
        this.http.del(this, {
          url: this.api.process.authDel,
          data: {
            processDefinitionId: this.queryParam.processDefinitionId,
            identityType: record.identityType,
            identityId: record.identityId
          },
          success: (me) => {
            this.$refs['table'].refresh(false)
          }
        })
      },
      handleSubmit() {
        this.$refs.form.submit({ processDefinitionId: this.queryParam.processDefinitionId }, this.handleCancel)
      },
      handleCancel() {
        this.authModal = false
      }
    },
    created() {

    }
  }
</script>
